//
//  PopAletView.m
//  XKStudyDemo
//
//  Created by xukai on 2017/11/30.
//  Copyright © 2017年 xukai. All rights reserved.
//

#import "PopAletView.h"

@interface PopAletView ()

@property(nonatomic,copy)NSString *title;
@property(nonatomic,copy)NSString *desc;
@property (nonatomic, strong) UIView *infoView;

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *detailLab;

@end

@implementation PopAletView

-(instancetype) initWithTitle:(NSString *) title detail:(NSString *) detail callBlock:(block) callBlock
{
   if(self = [super init])
    {
        _callBlock = callBlock;
        _title = title;
        _desc = detail;
        self.frame = CGRectMake(0, 0, SCREEN_WIDHT, SCREEN_HEIGHT);
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
        
        _infoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDHT * 0.5, 180)];
        _infoView.backgroundColor = [UIColor whiteColor];
        _infoView.center = CGPointMake(SCREEN_WIDHT * 0.5, SCREEN_HEIGHT * 0.5);
        [self addSubview:_infoView];
        
        
        _titleLab = [UILabel makeCommonWithFrame:CGRectMake(0, 0, _infoView.width, 40) textColor:ColorFromRGB(0x151515) bgColor:nil font:14 textAlignment:NSTextAlignmentCenter title:title];
        [_infoView addSubview:_titleLab];
        
        [_infoView drawLineWithSpoint:CGPointMake(20, 40) ePoint:CGPointMake(_infoView.width - 20, 40) W:1 colour:ColorFromRGB(0x999999)];
        

        
        UIButton *downBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, _infoView.width, 40)];
        downBtn.bottom = _infoView.height;
        [downBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [downBtn setTitle:@"确定" forState:(UIControlStateNormal)];
        [downBtn setBackgroundColor:[UIColor redColor]];
        [_infoView addSubview:downBtn];
        [downBtn addTarget:self action:@selector(downClick) forControlEvents:(UIControlEventTouchUpInside)];
        
        _detailLab = [UILabel makeCommonWithFrame:CGRectMake(10, _titleLab.bottom + 10, _infoView.width - 20, _infoView.height - _titleLab.height - downBtn.height - 10) textColor:ColorFromRGB(0x151515) bgColor:nil font:12 textAlignment:NSTextAlignmentCenter title:detail];
        [_infoView addSubview:_detailLab];
        
    }
    return self;
}

-(void) downClick
{
    [_infoView removeFromSuperview];
    [self removeFromSuperview];
    
}


-(void) show
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:self];
}

@end
